<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="车牌号查询" prop="carLicenseNumber">
        <el-input
          v-model="queryParams.carLicenseNumber"
          placeholder="请输入车牌号查询"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="操作员" prop="outOperatorName">
        <el-input
          v-model="queryParams.outOperatorName"
          placeholder="请输入操作员"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="进场时段" prop="enterStartTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.enterStartTime"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择开始时间">
        </el-date-picker>&ensp;-&ensp;
        <el-date-picker clearable size="small"
          v-model="queryParams.enterEndTime"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="出场时段" prop="leaveStartTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.leaveStartTime"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择开始时间">
        </el-date-picker>&ensp;-&ensp;
        <el-date-picker clearable size="small"
          v-model="queryParams.leaveEndTime"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="车辆开通类型" prop="leaveVipType">
        <el-select v-model="queryParams.leaveVipType" style="width: 100%"  placeholder="请选择车辆开通类型" filterable clearable size="small">
          <el-option
            v-for="dict in leaveVipTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="Number(dict.dictValue)"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="出场通道" prop="channelId">
        <el-select v-model="queryParams.channelId" style="width: 100%"  placeholder="请选择出场通道" filterable clearable size="small">
          <el-option
            v-for="channel in channelListOptions"
            :key="channel.channelCode"
            :label="channel.entranceName"
            :value="Number(channel.channelCode)"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
		      :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['system:parkLeave:exportLeaveRecord']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="parkLeaveList" border size="mini" stripe @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="离场记录表id" align="center" prop="id" v-if="false"/>
      <el-table-column label="停车记录编号" align="center" prop="parkingCode" width="260"/>
      <el-table-column label="停车场编号" align="center" prop="parkCode" width="135"/>
      <el-table-column label="出场通道" align="center" prop="leaveChannelName" width="135">
        <template slot-scope="scope">
          <span >【{{scope.row.leaveChannelName}}】{{scope.row.leaveChannelCode}}</span>
        </template>
      </el-table-column>
      <el-table-column label="停车时长" align="center" prop="parkingTime" />
      <el-table-column label="车牌号" align="center" prop="carLicenseNumber" />
      <el-table-column label="车辆开通类型" align="center" prop="leaveVipType" >
        <template slot-scope="scope">
          <span v-if="scope.row.leaveVipType == 1 " style="color: #58a1ad">临时车</span>
          <span v-if="scope.row.leaveVipType == 2 " style="color: red">固定车</span>
        </template>
      </el-table-column>
      <el-table-column label="停车费用" align="center" prop="totalAmount" />
      <el-table-column label="应收金额" align="center" prop="amountReceivable" />
      <el-table-column label="优惠金额" align="center" prop="discountAmount" />
      <el-table-column label="实付金额" align="center" prop="actualReceivable" />
      <el-table-column label="入场时间" align="center" prop="enterTime" width="135">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.enterTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="出场时间" align="center" prop="leaveTime" width="135">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.leaveTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="收费员" align="center" prop="tollCollectorName" />
      <el-table-column label="收费时间" align="center" prop="tollCollectTime" width="135">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.tollCollectTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="车牌图片" align="center" prop="plateImage" >
       <template slot-scope="scope">
         <img :src="scope.row.plateImage" alt="" width="100%" height="100%" @click="showImg(scope.row.plateImage)">
       </template>
      </el-table-column>
      <el-table-column label="车图片" align="center" prop="carImage" >
       <template slot-scope="scope">
         <img :src="scope.row.carImage" alt="" width="100%" height="100%" @click="showImg(scope.row.carImage)">
       </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!--  查看图片详情  -->
    <el-dialog :title="imgTitle" :visible.sync="imgOpen" v-if="imgOpen" width="50%" append-to-body>
     <show-imgs :imgs="imgUrl"></show-imgs>
    </el-dialog>

  </div>
</template>

<script>
import { leaveRecordList, exportLeaveRecord } from "@/api/system/parkLeave";
import {channelList } from "@/api/system/channelInfo";
import ShowImgs from "@/components/ShowImgs";

export default {
  name: "ParkLeave",
  components: {
    ShowImgs,
  },
  data() {
    return {
	  //按钮loading
	  buttonLoading: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      //停车费用对象
      priceTotal:{},
      // 总条数
      total: 0,
      // 车辆离场记录表格数据
      parkLeaveList: [],
      //通道下拉列表
      channelListOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 停车地方
      stopPlaceTypeOptions: [],
      // 进出场VIP类型
      leaveVipTypeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        carLicenseNumber: undefined,
        enterStartTime: undefined,
        enterEndTime: undefined,
        leaveStartTime: undefined,
        leaveEndTime: undefined,
        leaveVipType: undefined,
        channelId: undefined,
        outOperatorName: undefined,
        isType:1,
        type: undefined,
      },
      pickerOptions: {
        disabledDate(time){
          return time.getTime() > Date.now()
        }
      },
      imgOpen: false,
      imgTitle: "",
      imgUrl: "",
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getChannelList();
    this.getDicts("parking_is_type").then(response => {
      this.stopPlaceTypeOptions = response.data;
    });
    this.getDicts("parking_vip_type").then(response => {
      this.leaveVipTypeOptions = response.data;
    });
  },
  methods: {
    /** 查询车辆离场记录列表 */
    getList() {
      this.loading = true;
      leaveRecordList(this.queryParams).then(response => {
        this.parkLeaveList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询车辆离场记录列表 */
    getChannelList() {
      this.loading = true;
      channelList().then(response => {
        this.channelListOptions = response.data;
      });
    },
    //图片详情
    showImg(imgUrl) {
      this.imgOpen = true;
      this.imgTitle = "图片详情";
      this.imgUrl = imgUrl;
    },
    // 进出场类型
    stopPlaceTypeFormat(row, column) {
      return this.selectDictLabel(this.stopPlaceTypeOptions, row.type);
    },
    // 进出场VIP类型
    leaveVipTypeFormat(row, column) {
      return this.selectDictLabel(this.stopPlaceTypeOptions, row.leaveVipType);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.imgOpen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        carLicenseNumber: undefined,
        leaveTime: undefined,
        endLeaveTime: undefined,
        type: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if (this.compareTime(this.queryParams.leaveTime,this.queryParams.endLeaveTime) == false){
        this.msgError("请选择正确的时间段");
        return false;
      }
      this.getList();
      this.getPriceTotal();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有车辆离场记录数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportLeaveRecord(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
